﻿namespace App.Domain.Handlers {
    using System.Collections.Generic;
    using System.Linq;
    using App.Data;
    using App.Domain.Models;

    public class GetAllCompanies {
        private readonly ICompanyRepository _companyRepository;

        public GetAllCompanies(ICompanyRepository companyRepository) {
            _companyRepository = companyRepository;
        }

        public virtual IEnumerable<CompanyModel> Execute() {
            var companyData = _companyRepository.GetAll();

            var companies = from company in companyData
                            orderby company.CompanyName
                            select new CompanyModel(company.Id, company.CompanyName, company.ShortName, company.DateCreated);

            return companies;
        }
    }
}
